#include <phpcpp.h>
#include <iostream>

#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <thrift/stdcxx.h>

#include <gen-cpp/SharedService.h>

using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace std;

using namespace shared;

//Hbase连接
void HbaseClient(){
    boost::shared_ptr<TSocket> socket(new TSocket("120.132.60.101", 9090));
    boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
    boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

    SharedServiceClient client(protocol);

    transport->open();
}

//这是PHP里面可以调用的接口函数
void say_hello()
{
    //输出一段欢迎文字
    Php::out << "hello world from my first extension" << std::endl;
}






/**
 *  tell the compiler that the get_module is a pure C function
 */
extern "C" {
    
    /**
     *  Function that is called by PHP right after the PHP process
     *  has started, and that returns an address of an internal PHP
     *  strucure with all the details and features of your extension
     *
     *  @return void*   a pointer to an address that is understood by PHP
     */
    PHPCPP_EXPORT void *get_module() 
    {
        // static(!) Php::Extension object that should stay in memory
        // for the entire duration of the process (that's why it's static)
        static Php::Extension extension("HbaseClient", "1.0");
        
        // @todo    add your own functions, classes, namespaces to the extension
        //这里可以添加你要暴露给PHP调用的函数
        extension.add<say_hello>("say_hello");
        
        // return the extension
        return extension;
    }
}
